package com.jfs.qy.config.component;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Description 线程工厂
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/11/4
 */
public class TaskThreadFactory implements ThreadFactory {

    private final AtomicInteger THREAD_ID = new AtomicInteger(0);
    private final String name;

    public TaskThreadFactory(String name) {
        this.name = name;
    }

    @Override
    public Thread newThread(Runnable r) {
        String threadName = name + THREAD_ID.getAndIncrement();
        Thread thread = new Thread(r, threadName);
        thread.setDaemon(true);
        return thread;
    }
}
